import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *

testCase = "DBshop011_商品管理添加商品"
# 1.点击添加商品按钮，商品名称填写“苹果XR”,本店价格“7999”，商品类型“虚拟商品”。
firefox=openBrowser(urlAdmin) #调用函数打开网址
# 后台登录
DBshopLoginAdmin(firefox)
# 点击添加商品按钮
time.sleep(5)
firefox.find_element_by_link_text('添加商品').click()
time.sleep(3)
firefox.find_element_by_partial_link_text('添加商品').click()
time.sleep(10)
firefox.find_element_by_id('goods_name').send_keys('苹果XR')
time.sleep(10)
firefox.find_element_by_id('goods_shop_price').send_keys('7999')
time.sleep(3)
from selenium.webdriver.support.select import Select
s=Select(firefox.find_element_by_id('goods_type'))
s.select_by_visible_text('虚拟商品')
# 2.点击“保存商品”按钮，后台保存成功添加的商品。
time.sleep(3)
firefox.find_element_by_xpath('//button[@type="submit"]').click()
#断言
try:
    if firefox.find_element_by_xpath('//tbody/tr[2]/td[5]').text=="7999":
        writeLog("%s 测试通过"%testCase)
except:
    writeLog("%s 测试失败" % testCase)
    getPhoto(firefox)
firefox.quit()